/** 
 * @Title: DeptDAOImpl.java 
 * @Package com.prs.um.deptmanager.dao.impl 
 * @Description: 部门的接口实现类 
 * @author flybonew@163.com 
 * @date 2013-1-7 下午3:11:37 
 * @version V1.0 
 */  
package com.prs.um.deptmanager.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.prs.um.deptmanager.dao.DeptDAO;
import com.prs.um.deptmanager.dto.Dept;
import com.prs.um.dutymanager.dto.Duty;

/** 
 * @ClassName: DeptDAOImpl 
 * @Description: 部门接口的实现类 
 * @author flybonew@163.com
 * @date 2013-1-7 下午3:11:37 
 * 
 */
public class DeptDAOImpl implements DeptDAO {
	
	@Resource
	private HibernateTemplate hibernateTemplate;

	/*
	 * @Description: 添加部门 
	 * @author flybonew@163.com
	 * @date 2013-1-8 下午2:33:31 
	 */
	@Override
	public Dept addDept(Dept dept) {
		this.hibernateTemplate.save(dept);
		return dept;
	}

	/*
	 * @Description: 修改部门
	 * @author flybonew@163.com
	 * @date 2013-1-8 下午2:33:31 
	 */
	@Override
	public void updateDept(Dept dept) {
		this.hibernateTemplate.update(dept);
	}

	/*
	 * @Description: 删除部门
	 * @author flybonew@163.com
	 * @date 2013-1-8 下午2:33:31 
	 */
	@Override
	public void deleteDept(Dept dept) {
		this.hibernateTemplate.delete(dept);
	}

	/*
	 * @Description: 通过ID查询部门
	 * @author flybonew@163.com
	 * @date 2013-1-8 下午2:33:31 
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Dept selectDeptById(String deptId) {
		StringBuffer sql = new StringBuffer();
		sql.append("from Dept where 1=1 ");
		sql.append("and id_ = '"+ deptId+"'");
		final String typeSql = new String(sql);
		List<Dept> list = (List<Dept>)this.hibernateTemplate.find(typeSql);
		if(null != list && list.size() > 0){
			Dept dept = list.get(0);
			return dept;
		}
		return null;
	}

}
